<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      textarea {
        width: 500px;
        height: 100px;
      }
      .text {
        width: 500px;
        background-color: rgb(214, 236, 255);
        display: flex;
        justify-content: space-between;
      }
    </style>
  </head>
  <body>
    <textarea style="resize: none" placeholder="请输入评论"></textarea><br />
    <button id="btn">发布评论</button>

    <script>
      var btn = document.querySelector("#btn");

      btn.addEventListener("click", () => {
        var tArea = document.querySelector("textarea").value;
        console.log("🚀 ~ tArea:", tArea);
        var box = document.createElement("div");
        box.className = "text";
        box.innerHTML = `<span>${tArea}</span>
      <div><button>编辑</button><a class="del">删除</a></div>`;
        document.body.appendChild(box);

        var delall = document.querySelectorAll(".del");
        for (var i = 0; i < delall.length; i++) {
          delall[i].onclick = function () {
            // 弹出确认框，点击确定返回true
            if (confirm("确定删除吗？")) {
              this.parentNode.parentNode.remove();
            }
          };
        }
      });
    </script>
  </body>
</html>
